// src/main/java/cn/tom/test/t2/service/impl/ExcelServiceImpl.java
package cn.tom.service;

import cn.hutool.core.date.DateUtil;
import cn.tom.dao.ExprotMapper;
import cn.tom.entity.ExportVo;
import cn.tom.tool.MyExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {
    @Autowired
    ExprotMapper exprotMapper;
    @Override
    public void exportExcelData(int [] id ,HttpServletResponse response) {
        //List<Object> data = buildData();
        List list = new ArrayList();
        for (int i = 0; i < id.length; i++) {
            ExportVo exP1 = exprotMapper.findExP1(id[i]);
            list.add(exP1);
        }
        System.out.println("导出列表hhh1" +list);

        String today= DateUtil.today();
        String fileName =  "智能研发中心后台项目进度时标图" + today;
        new MyExcelUtil().exportData(list, fileName, response);
    }

    /*private List<Object> buildData() {
        List<Object> exportVos = new ArrayList<>();
        Date date = new Date();
        String formatDate = DateUtil.formatDate(date);

        // 构造第一条数据
        //List<ExportVo.ProjectGroupExcelVO> projectGroupList1 = new ArrayList<>();
        List<ProjectGroupExcelVO> projectGroupList1 = new ArrayList<>();
        //projectGroupList1.add(ExportVo.ProjectGroupExcelVO.builder()
        projectGroupList1.add(ProjectGroupExcelVO.builder()
                .name("界面效果程序编写|14")
                .leader("hhh21")
                .startDate(formatDate)
                .estimateDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .weekDay("22")
                .weekDay2("23")
                .problem("哈哈哈红红火火恍恍惚惚哈哈哈哈哈哈哈哈哈噶红红火火恍恍惚惚哈哈哈哈哈哈哈哈")
                .build());
        projectGroupList1.add(ProjectGroupExcelVO.builder()
                .name("小程序功能代码编写|10")
                .leader("hhh21")
                .startDate(formatDate)
                .estimateDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)
                .weekDay("22")
                .weekDay2("23")
                .build());
        projectGroupList1.add(ProjectGroupExcelVO.builder()
                .name("小程序功能代码编写|12")
                .leader("hhh21")
                .startDate(formatDate)
                .estimateDate(formatDate)
                .startDate2(formatDate)
                .endDate(formatDate)

                .build());

        ExportVo exportVo1 = ExportVo.builder()
                .name1("ZKDM156中置柜电动底盘画及接地开关智能控制器")
                .category("A")
                .name2("电动底盘车控制ＡＰＰ升级")
                .steps(projectGroupList1)
                .build();
        exportVos.add(exportVo1);
        //exportVos.add(exportVo2);
        return exportVos;
    }*/
}
